<?php 
//模型：缓存模块
//model/class.cache.php
//By QINIAO

class qiCache
{
	var $db;
	var $db_prefix;
	
	function qiCache($dbhandle,$db_prefix)
	{
		$this->db = $dbhandle;
		$this->db_prefix = $db_prefix;
	}
	
	//站点配置缓存
	function qc_options()
	{
	$options_cache = array();
	$res = $this->db->query("select * from ".$this->db_prefix."options");
	while($row = $this->db->fetch_array($res))
	{
	if(in_array($row['option_name'],array('site_key', 'blogname', 'bloginfo', 'blogurl', 'icp')))
	{
	$row['option_value'] = htmlspecialchars($row['option_value']);
	}
	$options_cache[$row['option_name']] = $row['option_value'];
	}
	$cacheData = serialize($options_cache);
	$this->cacheWrite($cacheData,'options');
	}
	
	//写入缓存
	function cacheWrite($cacheData,$cacheFile)
	{
	$cacheFile = QINIAO_ROOT.'/data/cache/'.$cacheFile;
	@ $fp = fopen($cacheFile,'wb') OR qiMsg('读取缓存失败。如果您使用的是Unix/Linux主机，请修改缓存目录 (data/cache) 下所有文件的权限为777。如果您使用的是Windows主机，请联系管理员，将该目录下所有文件设为everyone可写');
	@ $fw = fwrite($fp,$cacheData) OR qiMsg('写入缓存失败，缓存目录 (data/cache) 不可写');
	fclose($fp);
	}
	
	//读取缓存
	function cacheRead($cacheFile)
	{
	$cacheFile = QINIAO_ROOT.'/data/cache/'.$cacheFile;
	if(@$fp = fopen($cacheFile,'r'))
	{
	$data = fread($fp,filesize($cacheFile));
	fclose($fp);
	}
	return unserialize($data);
	}
	
	
	}
?>